 package com.tnl.app.service.impl;
 
 import java.util.Properties;

import javax.mail.internet.MimeMessage;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Repository;

import com.tnl.base.Const;
 
 @Repository
 public class MailService
 {
   private static final Logger logger = LoggerFactory.getLogger(MailService.class);
   
   public static String sendSimpleMail(String to,String position, String name,String phone)
   {
     JavaMailSenderImpl senderImpl = new JavaMailSenderImpl();
     
     senderImpl.setHost(Const.MAILHOST);
     
 
     SimpleMailMessage mailMessage = new SimpleMailMessage();
     
 
 
     mailMessage.setTo(to);
     mailMessage.setFrom(Const.MAILUID);
     mailMessage.setSubject(position+"职位收到一份新简历");
     mailMessage.setText(
    	"<html>" + 
    	"<body>" + 
    	"    <div  style='width: 100%;height: 100%;position: relative;'>" + 
    	"        <p style='padding-top: 40px;width: 100%;height: 44px;display: flex;align-items: center;justify-content: center;'>"+ 
    	"		<img src='https://headoffer.com/maillogo.png' style=' width: 80px;height: 35px;padding-right: 5px;'> 医人才|专业的医疗行业职场发展入口</p>" + 
    	"        <ul  style='margin-left: 200px;margin-top: 35px;'>" + 
    	"            <li style='margin-top: 15px;'>您好！</li>" + 
    	"            <li  style='margin-left: 40px;margin-top: 15px;'>您发布的<span >"+position+"</span> 收到了一份新简历，请及时处理！</li>" + 
    	"            <li  style='margin-left: 40px;margin-top: 15px;'>姓名：<span >"+name+"</span></li>" + 
    	"            <li  style='margin-left: 40px;margin-top: 15px;'>现任公司：罗氏生命科学</li>" + 
    	"            <li  style='margin-left: 40px;margin-top: 15px;'>现任职位：注册事务专员</li>" + 
    	"            <li  style='margin-left: 40px;margin-top: 15px;'>所在城市：<span >上海</span></li>" + 
    	"            <li  style='margin-left: 40px;margin-top: 15px;'>管理区域：<span >华东区</span></li>" + 
    	"            <li  style='margin-left: 40px;margin-top: 15px;'>联系方式：<span >"+phone+"</span> </li>" + 
    	"        </ul>" + 
    	"        <div  style='position: absolute;left: 50%;margin-left: -40px;display: flex;flex-direction: column;justify-content: center;'>"
    	+ "<img src='https://headoffer.com/mailheadoffer.png' style=' width: 80px;height: 80px;'>" + 
    	"            <p  style='margin-left: -47px;'>微信扫一扫在手机端处理</p>" + 
    	"        </div>" + 
    	"        <p  style=' position: absolute;bottom: 20px;left: 15px;font-size: 14px;color: red;margin-left: 150px;margin-bottom: 80px;'>本邮件为系统邮件，请勿直接回复！</p>" + 
    	"        <img src='https://headoffer.com/mailService.jpg'   style=' position: absolute; bottom: 45px;right: 45px;'>" + 
    	"        <p  style=' position: absolute; bottom: 10px;right: 5px;'>如有任何疑问请添加客服微信咨询</p>" + 
    	"    </div>" + 
    	"</body>"+
    	"</html>" );
     
     senderImpl.setUsername(Const.MAILUID);
     senderImpl.setPassword(Const.MAILKEY);
     
     Properties prop = new Properties();
     prop.put(" mail.smtp.auth ", " true ");
     prop.put(" mail.smtp.timeout ", " 25000 ");
     senderImpl.setJavaMailProperties(prop);
     
     senderImpl.send(mailMessage);
     
     logger.info(" 邮件发送成功.. ");
     return "Success";
   }
   
   public void sendMail(String to,String position, String name,String phone) {
	   	JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
	   	javaMailSender.setHost(Const.MAILHOST);
       try {
           MimeMessage mimeMessage = javaMailSender.createMimeMessage();
         
           MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage,true,"UTF-8");
           messageHelper.setFrom(Const.MAILUID); //设置发件人Email
           messageHelper.setSubject(position+"职位收到一份新简历"); //设置邮件主题
           messageHelper.setTo(to);          //设定收件人Email
           messageHelper.setText(
        		   "<html style='width:100%;height:100%;'>" + 
        			    	"<body style='width:100%;height:100%;'>" + 
        			    	"    <div  style='width: 100%;height: 100%;position: relative;'>" + 
        			    	"        <p style='padding-top: 40px;width: 100%;height: 44px;display: flex;align-items: center;justify-content: center;'>"+ 
        			    	"		<img src='https://headoffer.com/maillogo.png' style=' width: 80px;height: 35px;padding-right: 5px;'> 医人才|专业的医疗行业职场发展入口</p>" + 
        			    	"        <ul  style='margin-left: 200px;margin-top: 35px;'>" + 
        			    	"            <li style='margin-top: 15px;list-style:none;'>您好！</li>" + 
        			    	"            <li  style='margin-left: 40px;margin-top: 15px;list-style:none;'>您发布的<span >"+position+"</span> 收到了一份新简历，请及时处理！</li>" + 
        			    	"            <li  style='margin-left: 40px;margin-top: 15px;'>姓名：<span >"+name+"</span></li>" + 
        			    	"            <li  style='margin-left: 40px;margin-top: 15px;'>现任公司：罗氏生命科学</li>" + 
        			    	"            <li  style='margin-left: 40px;margin-top: 15px;'>现任职位：注册事务专员</li>" + 
        			    	"            <li  style='margin-left: 40px;margin-top: 15px;'>所在城市：<span >上海</span></li>" + 
        			    	"            <li  style='margin-left: 40px;margin-top: 15px;'>管理区域：<span >华东区</span></li>" + 
        			    	"            <li  style='margin-left: 40px;margin-top: 15px;'>联系方式：<span >"+phone+"</span> </li>" + 
        			    	"        </ul>" + 
        			    	"        <div  style='position: absolute;left: 50%;margin-left: -40px;display: flex;flex-direction: column;justify-content: center;'>"
        			    	+ "<img src='https://headoffer.com/mailheadoffer.png' style=' width: 80px;height: 80px;'>" + 
        			    	"            <p  style='margin-left: -15px;font-size:10px;'>微信扫一扫在手机端处理</p>" + 
        			    	"        </div>" + 
        			    	"        <p  style=' position: absolute;bottom: 20px;left: 15px;font-size: 14px;color: red;margin-left: 150px;margin-bottom: 80px;'>本邮件为系统邮件，请勿直接回复！</p>" + 
        			    	"        <img src='https://headoffer.com/mailService.jpg'   style=' position: absolute; bottom: 45px;right: 45px;'>" + 
        			    	"        <p  style=' position: absolute; bottom: 10px;right: 5px;'>如有任何疑问请添加客服微信咨询</p>" + 
        			    	"    </div>" + 
        			    	"</body>"+
        			    	"</html>",true
        		   );   //设置邮件主题内容
           
           javaMailSender.setUsername(Const.MAILUID);
           javaMailSender.setPassword(Const.MAILKEY);
           
           Properties prop = new Properties();
           prop.put(" mail.smtp.auth ", " true ");
           prop.put(" mail.smtp.timeout ", " 25000 ");
           javaMailSender.setJavaMailProperties(prop);
           javaMailSender.send(mimeMessage);    //发送HTML邮件
           logger.info(" 邮件发送成功.. ");
       } catch (Exception e) {
           System.out.println("异常信息：" + e);
       }
   }
   

   public static void main(String[] args) {
	  // sendMail("he@trend-china.com", "产品经理", "");
   }
 }


